from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

# 调到 admin 主页面
def index(request):
    return render(request,'admin/index.html')

# 文件写入  用户头像
def uploads(myfile):
    import time,os,random
    filename = str(time.time())+str(random.randint(10000,99999))+"."+myfile.name.split('.')[-1]
    destination = open("./static/pics/"+filename,"wb+")
    for chunk in myfile.chunks():      # 分块写入文件  
        destination.write(chunk)  
    destination.close()

    return "/static/pics/"+filename

# 文件写入  商品图片
def upgoods(myfile):
    import time,os,random
    filename = str(time.time())+str(random.randint(10000,99999))+"."+myfile.name.split('.')[-1]
    destination = open("./static/pics/goodimg/"+filename,"wb+")
    for chunk in myfile.chunks():      # 分块写入文件  
        destination.write(chunk)  
    destination.close()
    return "/static/pics/goodimg/"+filename



        







